package com.nine.aop.exception.handler;

import com.nine.aop.exception.CustomException;
import com.nine.aop.result.R;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 自定义异常处理器
 */
@Slf4j
@RestControllerAdvice
public class CustomExceptionHandler {

    @ExceptionHandler(CustomException.class)
    public R<Void> handleException(CustomException e, HttpServletRequest request) {
        String requestURI = request.getRequestURI();
        log.error("请求地址'{}',存在错误'{}'", requestURI, e.getMessage());
        return R.fail("系统异常");
    }

}
